# coding: utf8
# try something like
def index():
    donors = db().select(db.donor.ALL, orderby=db.donor.last_name)
    return dict(donors=donors)

def add__new_donor_address():
    donor = db(db.donor.id==request.args(0)).select()[0]
    form = SQLFORM(db.address)
    form.vars.donor_id = donor.id
    if form.accepts(request.vars, session):
        response.flash = T('new address added')
    addresses = db(db.address.donor_id==donor.id).select()
    return dict(donor=donor, addresses=addresses, form=form)

def list_donor_addresses(): 
    # get donor id
    donor = db(db.donor.id==request.args(0)).select()[0]
    addresses = db(db.address.donor_id==donor.id).select()
    return dict(donor=donor, addresses=addresses)
